{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# python notebook for Make Your Own Neural Network\n",
    "# working with the MNIST data set\n",
    "#\n",
    "# (c) Tariq Rashid, 2016\n",
    "# license is GPLv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import matplotlib.pyplot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# open the CSV file and read its contents into a list\n",
    "data_file = open(\"mnist_dataset/mnist_train_100.csv\", 'r')\n",
    "data_list = data_file.readlines()\n",
    "data_file.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# check the number of data records (examples)\n",
    "len(data_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,159,253,159,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,238,252,252,252,237,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,54,227,253,252,239,233,252,57,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,60,224,252,253,252,202,84,252,253,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,163,252,252,252,253,252,252,96,189,253,167,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,238,253,253,190,114,253,228,47,79,255,168,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,238,252,252,179,12,75,121,21,0,0,253,243,50,0,0,0,0,0,0,0,0,0,0,0,0,0,38,165,253,233,208,84,0,0,0,0,0,0,253,252,165,0,0,0,0,0,0,0,0,0,0,0,0,7,178,252,240,71,19,28,0,0,0,0,0,0,253,252,195,0,0,0,0,0,0,0,0,0,0,0,0,57,252,252,63,0,0,0,0,0,0,0,0,0,253,252,195,0,0,0,0,0,0,0,0,0,0,0,0,198,253,190,0,0,0,0,0,0,0,0,0,0,255,253,196,0,0,0,0,0,0,0,0,0,0,0,76,246,252,112,0,0,0,0,0,0,0,0,0,0,253,252,148,0,0,0,0,0,0,0,0,0,0,0,85,252,230,25,0,0,0,0,0,0,0,0,7,135,253,186,12,0,0,0,0,0,0,0,0,0,0,0,85,252,223,0,0,0,0,0,0,0,0,7,131,252,225,71,0,0,0,0,0,0,0,0,0,0,0,0,85,252,145,0,0,0,0,0,0,0,48,165,252,173,0,0,0,0,0,0,0,0,0,0,0,0,0,0,86,253,225,0,0,0,0,0,0,114,238,253,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,252,249,146,48,29,85,178,225,253,223,167,56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,252,252,252,229,215,252,252,252,196,130,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,199,252,252,253,252,252,233,145,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,128,252,253,252,141,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\\n'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show a dataset record\n",
    "# the first number is the label, the rest are pixel colour values (greyscale 0-255)\n",
    "data_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x12e810e60>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAcOElEQVR4nO3df2zU9R3H8deB9ARtD0ttrycFC/7AidQMpTYqw9FAu8UIskX8sYAhGLGowPwRnIg6l07M1OEQN7PRGQWdRiCaDKPFlrm1LCCEoVtDWZXyo0WJvStFSqWf/UG4eVCE73HXd3s8H8kl9O777vfj10uffLm7b33OOScAALpZH+sFAADOTAQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYOMt6Acfq7OzU7t27lZ6eLp/PZ70cAIBHzjm1trYqFAqpT58Tn+f0uADt3r1beXl51ssAAJymxsZGDR48+ISP97gApaenSzqy8IyMDOPVAAC8ikQiysvLi/48P5GkBWjJkiV65pln1NTUpIKCAr3wwgsaM2bMSeeO/rNbRkYGAQKAXuxkL6Mk5U0Ib7zxhubNm6eFCxfq448/VkFBgSZOnKi9e/cmY3cAgF4oKQF69tlnNXPmTN1555363ve+p5deekkDBgzQn/70p2TsDgDQCyU8QIcOHdLGjRt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wbm5vsXQEAepGEB+iBBx5QdXW1PvvsM/3jH//Q5MmT1bdvX916662J3hUAoBdL+D/B7dy5U7feeqv27dun888/X9ddd51qa2t1/vnnJ3pXAIBeLOEBev311xP9LYEe7fPPP/c8M27cOM8zX331lecZn8/neUaSAoGA55l4Xsvdu3ev55n//ve/nmeGDh3qeUaS+vbtG9ccTg3XggMAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATCT9F9IBFjo6OuKai+fCoiUlJZ5nGhsbPc90pyuvvNLzzK9+9SvPM9ddd53nmYsvvtjzzB/+8AfPM5K6/C3OSBzOgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCq2EjJT344INxzf3ud79L8Ep6p+rqas8zbW1tnmcmT57seebtt9/2PLNp0ybPM0g+zoAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABNcjBQ9XmNjo+eZV199Na59OefimvMqnotwTpkyxfPMHXfc4XlGkvLy8jzPXHbZZZ5nHn74Yc8zb731lueZ7vr/Cm84AwIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATPhcD7tKXyQSUSAQUDgcVkZGhvVykGC7du3yPFNQUOB5pqWlxfNMvG6//XbPMy+//LLnmU8//dTzzMcff+x5RpKmTp3qeWbAgAFx7curvn37ep4555xz4trXJ5984nkmngu5pppT/TnOGRAAwAQBAgCY8BygdevW6cYbb1QoFJLP59OqVatiHnfO6bHHHlNubq769++v4uJibdu2LVHrBQCkCM8BamtrU0FBgZYsWdLl44sWLdLixYv10ksvaf369TrnnHM0ceJEHTx48LQXCwBIHZ5/I2ppaalKS0u7fMw5p+eff16PPvqobrrpJknSK6+8opycHK1atSquFzYBAKkpoa8BNTQ0qKmpScXFxdH7AoGACgsLVVNT0+VMe3u7IpFIzA0AkPoSGqCmpiZJUk5OTsz9OTk50ceOVV5erkAgEL3xFkYAODOYvwtu/vz5CofD0VtjY6P1kgAA3SChAQoGg5Kk5ubmmPubm5ujjx3L7/crIyMj5gYASH0JDVB+fr6CwaAqKyuj90UiEa1fv15FRUWJ3BUAoJfz/C64/fv3q76+Pvp1Q0ODNm/erMzMTA0ZMkRz5szRU089pYsvvlj5+flasGCBQqGQJk2alMh1AwB6Oc8B2rBhg2644Ybo1/PmzZMkTZs2TRUVFXrooYfU1tamu+66Sy0tLbruuuu0Zs0anX322YlbNQCg1+NipIjbl19+6XnmySef9Dxzog89f5dj34l5qvLz8z3P/OY3v/E8c80113iewRHxXIzU5/PFta977rnH88zixYvj2lcq4WKkAIAejQABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACY8/zoGpJ5vvvkmrrkHHnjA88yrr77qeSYQCHieee+99zzPSNJFF13keaajoyOufaHna2hosF5CSuMMCABgggABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwwcVIoR07dsQ1F8+FReNRW1vreeaSSy5Jwkq61r9//27bF5BKOAMCAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAExwMVKorKwsrjnnnOeZyZMne57pzguLoufr7Oz0PNOnT3x/147nOY5TxxkQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCi5GmmE2bNnmeWbduXVz78vl8nmd++tOfxrUv4Kh4Liwaz3NVkq666qq45nBqOAMCAJggQAAAE54DtG7dOt14440KhULy+XxatWpVzOPTp0+Xz+eLuZWUlCRqvQCAFOE5QG1tbSooKNCSJUtOuE1JSYn27NkTva1YseK0FgkASD2e34RQWlqq0tLS79zG7/crGAzGvSgAQOpLymtAVVVVys7O1qWXXqpZs2Zp3759J9y2vb1dkU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HcByO4DgcwXE4oiccB+ecWltbFQqF1KfPiV/p6XFnQH369NHgwYO/c5uMjIwz+gl2FMfhCI7DERyHIzgOR1gfh+868zmKNyEAAEwQIACAiV4VIL/fr4ULF8rv91svxRTH4QiOwxEchyM4Dkf0puPQ496EAAA4M/SqMyAAQOogQAAAEwQIAGCCAAEATPSaAC1ZskQXXnihzj77bBUWFuqf//yn9ZK63eOPPy6fzxdzGzFihPWykm7dunW68cYbFQqF5PP5tGrVqpjHnXN67LHHlJubq/79+6u4uFjbtm2zWWwSnew4TJ8+/bjnR0lJic1ik6S8vFxXX3210tPTlZ2drUmTJqmuri5mm4MHD6qsrEyDBg3SueeeqylTpqi5udloxclxKsdh3Lhxxz0f7r77bqMVd61XBOiNN97QvHnztHDhQn388ccqKCjQxIkTtXfvXuuldbvLL79ce/bsid4++ugj6yUlXVtbmwoKCrRkyZIuH1+0aJEWL16sl156SevXr9c555yjiRMn6uDBg9280uQ62XGQpJKSkpjnx4oVK7pxhclXXV2tsrIy1dbW6v3331dHR4cmTJigtra26DZz587VO++8ozfffFPV1dXavXu3br75ZsNVJ96pHAdJmjlzZszzYdGiRUYrPgHXC4wZM8aVlZVFvz58+LALhUKuvLzccFXdb+HCha6goMB6GaYkuZUrV0a/7uzsdMFg0D3zzDPR+1paWpzf73crVqwwWGH3OPY4OOfctGnT3E033WSyHit79+51klx1dbVz7sj/+379+rk333wzus2///1vJ8nV1NRYLTPpjj0Ozjn3gx/8wN1///12izoFPf4M6NChQ9q4caOKi4uj9/Xp00fFxcWqqakxXJmNbdu2KRQKadiwYbr99tu1Y8cO6yWZamhoUFNTU8zzIxAIqLCw8Ix8flRVVSk7O1uXXnqpZs2apX379lkvKanC4bAkKTMzU5K0ceNGdXR0xDwfRowYoSFDhqT08+HY43DUa6+9pqysLI0cOVLz58/XgQMHLJZ3Qj3uYqTH+vLLL3X48GHl5OTE3J+Tk6P//Oc/RquyUVhYqIqKCl166aXas2ePnnjiCV1//fXaunWr0tPTrZdnoqmp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GDHCTJ092e/bssVt0EpzsOOzYscONHTvWZWZmOr/f7y666CL34IMPunA4bLvwY/DrGAAAJnr8a0AAgNREgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJj4HzCIHEC6t1ufAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# take the data from a record, rearrange it into a 28*28 array and plot it as an image\n",
    "all_values = data_list[1].split(',')\n",
    "image_array = numpy.asfarray(all_values[1:]).reshape((28,28))\n",
    "matplotlib.pyplot.imshow(image_array, cmap='Greys', interpolation='None')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.208      0.62729412 0.99223529 0.62729412 0.20411765\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.19635294 0.934\n",
      " 0.98835294 0.98835294 0.98835294 0.93011765 0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.21964706 0.89129412 0.99223529 0.98835294 0.93788235\n",
      " 0.91458824 0.98835294 0.23129412 0.03329412 0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.04882353 0.24294118 0.87964706\n",
      " 0.98835294 0.99223529 0.98835294 0.79423529 0.33611765 0.98835294\n",
      " 0.99223529 0.48364706 0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.64282353 0.98835294 0.98835294 0.98835294 0.99223529\n",
      " 0.98835294 0.98835294 0.38270588 0.74376471 0.99223529 0.65835294\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.208      0.934\n",
      " 0.99223529 0.99223529 0.74764706 0.45258824 0.99223529 0.89517647\n",
      " 0.19247059 0.31670588 1.         0.66223529 0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.19635294 0.934      0.98835294 0.98835294 0.70494118\n",
      " 0.05658824 0.30117647 0.47976471 0.09152941 0.01       0.01\n",
      " 0.99223529 0.95341176 0.20411765 0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.15752941 0.65058824\n",
      " 0.99223529 0.91458824 0.81752941 0.33611765 0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.99223529 0.98835294\n",
      " 0.65058824 0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.03717647 0.70105882 0.98835294 0.94176471 0.28564706\n",
      " 0.08376471 0.11870588 0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.99223529 0.98835294 0.76705882 0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.23129412\n",
      " 0.98835294 0.98835294 0.25458824 0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.99223529 0.98835294 0.76705882 0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.77870588 0.99223529 0.74764706\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       1.         0.99223529\n",
      " 0.77094118 0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.30505882 0.96505882 0.98835294 0.44482353 0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.99223529 0.98835294 0.58458824 0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.34       0.98835294\n",
      " 0.90294118 0.10705882 0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.03717647 0.53411765\n",
      " 0.99223529 0.73211765 0.05658824 0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.34       0.98835294 0.87576471 0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.03717647 0.51858824 0.98835294 0.88352941 0.28564706\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.34       0.98835294 0.57294118 0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.19635294 0.65058824\n",
      " 0.98835294 0.68164706 0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.34388235 0.99223529\n",
      " 0.88352941 0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.45258824 0.934      0.99223529 0.63894118 0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.34       0.98835294 0.97670588 0.57682353\n",
      " 0.19635294 0.12258824 0.34       0.70105882 0.88352941 0.99223529\n",
      " 0.87576471 0.65835294 0.22741176 0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.34       0.98835294 0.98835294 0.98835294 0.89905882 0.84470588\n",
      " 0.98835294 0.98835294 0.98835294 0.77094118 0.51470588 0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.11870588 0.78258824\n",
      " 0.98835294 0.98835294 0.99223529 0.98835294 0.98835294 0.91458824\n",
      " 0.57294118 0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.10705882 0.50694118 0.98835294\n",
      " 0.99223529 0.98835294 0.55741176 0.15364706 0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01       0.01       0.01\n",
      " 0.01       0.01       0.01       0.01      ]\n"
     ]
    }
   ],
   "source": [
    "# scale input to range 0.01 to 1.00\n",
    "scaled_input = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01\n",
    "print(scaled_input)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#output nodes is 10 (example)\n",
    "onodes = 10\n",
    "targets = numpy.zeros(onodes) + 0.01\n",
    "targets[int(all_values[0])] = 0.99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.99 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01]\n"
     ]
    }
   ],
   "source": [
    "print(targets)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
